/**
 * 2017年5月4日
 */
package cn.edu.bjtu.classification;

import cn.edu.bjtu.general.math.Arrays;

/**
 * @author Alex
 *
 */
public class LibSVMClassificationResult implements ClassificationResult{
	private static final String literalLable[] = new String[]{ 
				"政治军事",
				"文化宗教", 
				"时尚设计", 
				"教育",
				"育儿", 
				"农业与环境",
				"生活",
				"社会", 
				"科技",
				"体育娱乐", 
				"能源地产", 
				"旅游", 
				"财经", 
				"广告", 
				"其他", 
	};
	int [] label;
	double distribution[];
	int trueLabel;
	String instanceId;
	public int[] getTopKIndex(int k){
		int res[] = new int[k];
		for(int i=0;i<k;i++){
			double max=-1;
			for(int j=0;j<distribution.length;j++){
				boolean flag = false;
				for(int x=0;x<i;x++){
					if(res[x] == j)flag=true;
				}
				if(flag) continue;
				else{
					if(distribution[j]>max){
						max = distribution[j];
						res[i] = j;
					}
					
				}
			}
			max = -1;
		}
		return res;
	}	
	public static void main(String args[]){
		LibSVMClassificationResult res = new LibSVMClassificationResult();
		res.distribution = new double []{4.0,2.5,7.0,4.0,2.1};
		System.out.println(Arrays.toString(res.getTopKIndex(3)));
	}
	public int[] getLabel() {
		return label;
	}
	public void setLabel(int[] label) {
		this.label = label;
	}
	public double[] getDistribution() {
		return distribution;
	}
	public void setDistribution(double[] distribution) {
		this.distribution = distribution;
	}
	public int getTrueLabel() {
		return trueLabel;
	}
	public void setTrueLabel(int trueLabel) {
		this.trueLabel = trueLabel;
	}
	public String getInstanceId() {
		return instanceId;
	}
	public void setInstanceId(String instanceId) {
		this.instanceId = instanceId;
	}
	public String toClassLabelDescription(){
		int [] res = this.getTopKIndex(3);
		String result = "";
		for(int i=0;i<res.length;i++){
			result += literalLable[label[res[i]]-1];
			result += ",";
		}
		return result;
		
	}
	
}
